import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:provider/provider.dart';
import 'package:study_online/global/colors.dart';
import 'package:study_online/utils/jh_login_textfield.dart';
import 'MedicineInstituteTab.dart';
import 'InformationScienceTab.dart';
import 'RecommendTab.dart';

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  const MyApp({Key key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        //appBar: AppBar(
        //  backgroundColor: Colors.black26,
        //  title: Text('container'),
        //),
        body: HomePage(),
      ),
    );
  }
}
class HomePage extends StatefulWidget {
  HomePage({Key key}) : super(key: key);

  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> with AutomaticKeepAliveClientMixin{
  final List<Widget> _tabs = [
    Tab(text: "推荐"),
    Tab(text: "信科院"),
    Tab(text: "药学院"),
    Tab(text: "医学院"),
    Tab(text: "护理学院"),
    Tab(text: "湘杏学院"),
    Tab(text: "文管院"),
    Tab(text: "中医学院"),
  ];
  final List<Widget> _tabViews = [
    RecommendTab(),
    InformationScienceTab(),
    MedicineInstituteTab(),
    Text('临床'),
    Text('针推'),
    Text('护理学'),
    Text('公共管理'),
    Text('中医学'),
  ];

  @override
  Widget build(BuildContext context) {
    ScreenUtil.init(
      BoxConstraints(
          maxWidth: MediaQuery.of(context).size.width,
          maxHeight: MediaQuery.of(context).size.height),
      designSize: Size(476, 922),
    );
    return Scaffold(
      appBar: _appBar(),
      body: Container(
        color: Color(0xffF1F2F2),
        child: DefaultTabController(
          length: _tabs.length,
          child: Scaffold(
            appBar: _tabBar(),
            body: TabBarView(
              children: _tabViews,
            ),
          ),
        ),
      ),
    );
  }

  Widget _appBar() {
    return PreferredSize(
      preferredSize: Size.fromHeight(ScreenUtil().setHeight(58)),
      child: AppBar(
        backgroundColor: Colors.white,
        titleSpacing: 15,
        elevation: 0,
        automaticallyImplyLeading: false,
        //隐藏返回箭头
        title: Row(
          children: [
            // Image.asset(
            //   'assets/img/icon.png',
            //   width: ScreenUtil().setHeight(35),
            //   height: ScreenUtil().setHeight(35),
            //   fit: BoxFit.cover,
            // ),
            Text(
              'E-Future',
              style: TextStyle(
                fontSize: ScreenUtil().setSp(25),
                color: AppColors.primary,
              ),
            ),
            SizedBox(
              width: ScreenUtil().setWidth(20),
            ),
            Container(
              width: ScreenUtil().setWidth(326),
              child: Container(
                decoration: new BoxDecoration(
                  color: Color(0xffF1F2F2),
                  borderRadius: BorderRadius.all(
                    Radius.circular(25.0),
                  ),
                ),
                alignment: Alignment.center,
                height: ScreenUtil().setHeight(40),
                child: JhLoginTextField(
                  border: InputBorder.none,
                  leftWidget: InkWell(
                    child: Container(
                        padding: EdgeInsets.all(8),
                        child: Icon(
                          Icons.search,
                          color: AppColors.subtext,
                        )),
                    onTap: () {},
                  ),
                  hintText: 'springboot+mybatis+flutter',
                  isShowDeleteBtn: true,
                  isDense: false,
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }

  Widget _tabBar() {
    return TabBar(
      tabs: _tabs,
      labelColor: AppColors.primary,
      labelStyle: TextStyle(
          fontWeight: FontWeight.bold,
          fontSize: ScreenUtil().setSp(25),
          fontFamily: '方正御墨行书'),
      unselectedLabelColor: Colors.black,
      unselectedLabelStyle:
          TextStyle(fontSize: ScreenUtil().setSp(18), fontFamily: '方正御墨行书'),
      indicatorSize: TabBarIndicatorSize.tab,
      indicatorColor: AppColors.primary,
      indicatorWeight: 4,
      isScrollable: true,
    );
  }

  @override
  // TODO: implement wantKeepAlive
  bool get wantKeepAlive => true;
}
